package org.wtframework.platform.server.service;

import java.util.List;

import org.openredhead.springx.core.server.manager.IBasicManager;
import org.openredhead.springx.core.server.model.support.UpdateCompositorObject;
import org.openredhead.springx.core.web.mvc.ajaxrpc.BasicAjaxRpcRemoteService;
import org.openredhead.springx.core.web.mvc.annotation.AjaxRpcMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.wtframework.platform.server.manager.impl.ResourceManager;
import org.wtframework.platform.server.model.impl.Resource;

/**
 * 
 * <B>类描述：</B> （共用的开放方法Service） <br/><br/>
 * <B>作者：</B> 梁卓文<br/><br/>
 * <B>创建日期：</B> 2014年5月7日 上午11:04:09 
 *
 */
@Service
public class BaseService extends BasicAjaxRpcRemoteService {
	
	@Autowired
	protected ApplicationContext applicationContext;
	
	@Autowired
	protected ResourceManager resourceManager;
	
	/**
	 * 
	 * <B>方法描述：</B>（通用的更新对象的orderId） <br/>
	 *
	 * <B>作者：	 </B> 梁卓文 <br/>
	 * @param simpleCompositorObject
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@AjaxRpcMethod
	public void updateOrder(String managerName, List<UpdateCompositorObject> simpleCompositorObject) {
		
		IBasicManager IBasicManager = (IBasicManager) applicationContext.getBean(managerName);
		IBasicManager.updateOrder(simpleCompositorObject);
	}

	/**
	 * 
	 * <B>方法描述：</B>（判断当前用户是否有这个权限） <br/>
	 *
	 * <B>作者：	 </B> 梁卓文 <br/>
	 * @param pIdentity
	 * @param identity
	 * @return
	 */
	public Boolean isHaveResource(String pIdentity, String identity) {
		
		for(Resource r : resourceManager.getLoginUserChildPermissionResources(pIdentity)) {
			if(r.getIdentifier().equals(identity)) {
				return true;
			}			
		}
		return false;
	}
}
